/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.member;

import java.util.*;




import javax.servlet.*;
import javax.servlet.http.*;

import org.json.simple.JSONObject;

import com.zll.framework.conf.Configuration;
import com.zll.framework.model.HashBox;
import com.zll.framework.model.HashList;
import com.zll.framework.servlet.Command;
import com.zll.framework.util.EmailUtil;
import com.qbooks.common.CommonDAO;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class FindPasswordCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	JSONObject json = new JSONObject();

		HashBox box = new HashBox(request);

		MemberDAO dao 		= new MemberDAO();

		box.put("status", "1");
		HashList list = dao.selectMemberList(box.getParam());

		if (list.size() == 1) {
			String member_pw = list.get("member_pw", 0);
			
			//비밀번호 메일전송
			String from = Configuration.get("smtp.from");
			String fromName = "큐북스";
			
	        // 보내는이 메일주소
	        String to = list.get("member_id", 0);
	        // 받는이 이메일 주소는 반드시 ","로 구분해준다. String to = "받을 이메일 주소1,받을 이메일 주소2";
	        
	        String subject = "비밀번호찾기";
	        String content = list.get("member_name",0) + "회원님의 비밀번호는 " + member_pw + " 입니다.";


	        EmailUtil emailSender = new EmailUtil();
	        emailSender.sendEmail(from, fromName, to, subject, content);
	        
	        
			json.put("result", true);

		} else {
			json.put("result", false);
			json.put("message", "존재하지 않는 회원입니다");
		}

		request.setAttribute("jsonData", json.toString());


    	return "/common/json_view.jsp";
    }
}
